package h0913;

import java.util.HashMap;
import java.util.LinkedList;

public class JudgeBracket{
    public static void main(String[] args) {

    }
    public boolean isValid(String s) {
        // 请在这里实现你的代码
        HashMap<Character, Character> map = new HashMap<>();
        map.put('(',')');
        map.put('[',']');
        map.put('{','}');

        LinkedList<Character> stack = new LinkedList<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (map.containsKey(c)){
                stack.addLast(c);
            }else {
                if (stack.isEmpty()){
                    return false;
                }else if (map.get(stack.peekLast())!=c){
                    return false;
                }else {
                    stack.removeLast();
                }
            }
        }
        return stack.isEmpty();
    }

}

